package com.engine.topyoung.duss.util;

import com.alibaba.fastjson.JSONArray;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;

/**
 * @Title: Ecology9
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2021-09-24
 * @Description: 任务报表工具类
 * @ModifyLog:
 **/

public class TaskReportUtil {
    /**
    *如果实际完成日期有值，则用实际完成日期减去计划完成日期，天数为0-14则为1倍，后面超过5天翻倍。
    * 若无值，则计算当前日期减去计划完成日期，
    *天数为0-14则为1倍，后面超过5天翻倍。*/
    public static String getMultipleDays(String days){
        int newDays = 0;
        if(CalUtil.fCompare(CalUtil.fDivide(days,"14"),"0")>1){
            int btw = Util.getIntValue(days)%14;
            newDays = btw/5+1;
        }else{
            newDays = 1;
        }
        return newDays+"";
    }

    public static JSONArray getFzDetail(String departmentid,String year){
        JSONArray jsonArray = new JSONArray();
        RecordSet rs = new RecordSet();
        BaseBean baseBean = new BaseBean();
        //1-12月
        String one = "0";
        String two = "0";
        String thre = "0";
        String fou = "0";
        String fiv = "0";
        String six = "0";
        String sev = "0";
        String eig = "0";
        String nig = "0";
        String ten = "0";
        String ele = "0";
        String twef = "0";
        String sql = "select isnull(cast(fz as DECIMAL(38,2)),0) as fz," +
                "month(jhksrq) jhksrq,month(jhjsrq) jhjsrq from uf_bmzrw where bm = ? and left(jhksrq,4)= ? and rwzt !=5";
        rs.executeQuery(sql,departmentid,year);
        baseBean.writeLog(sql+","+departmentid+","+year);
        while (rs.next()){
            int jhksrq = Util.getIntValue(rs.getString("jhksrq"));
            int jhjsrq = Util.getIntValue(rs.getString("jhjsrq"));
            String fz = Util.null2String(rs.getString("fz"));
            baseBean.writeLog("jhksrq=",jhksrq);
            baseBean.writeLog("jhjsrq=",jhjsrq);
            baseBean.writeLog("fz=",fz);
            String avgfz = fz;
            for(int i = jhksrq;i<=jhjsrq;i++) {
                switch (i) {
                    case 1:
                        one = CalUtil.fAdd( one, avgfz );
                        break;
                    case 2:
                        two = CalUtil.fAdd( two, avgfz );
                        break;
                    case 3:
                        thre = CalUtil.fAdd( thre, avgfz );
                        break;
                    case 4:
                        fou = CalUtil.fAdd( fou, avgfz );
                        break;
                    case 5:
                        fiv = CalUtil.fAdd( fiv, avgfz );
                        break;
                    case 6:
                        six = CalUtil.fAdd( six, avgfz );
                        break;
                    case 7:
                        sev = CalUtil.fAdd( sev, avgfz );
                        break;
                    case 8:
                        eig = CalUtil.fAdd( eig, avgfz );
                        break;
                    case 9:
                        nig = CalUtil.fAdd( nig, avgfz );
                        break;
                    case 10:
                        ten = CalUtil.fAdd( ten, avgfz );
                        break;
                    case 11:
                        ele = CalUtil.fAdd( ele, avgfz );
                        break;
                    case 12:
                        twef = CalUtil.fAdd( twef, avgfz );
                        break;
                    default:
                }
            }
        }

        jsonArray.add(one);
        jsonArray.add(two);
        jsonArray.add(thre);
        jsonArray.add(fou);
        jsonArray.add(fiv);
        jsonArray.add(six);
        jsonArray.add(sev);
        jsonArray.add(eig);
        jsonArray.add(nig);
        jsonArray.add(ten);
        jsonArray.add(ele);
        jsonArray.add(twef);
        return jsonArray;
    }

    public static JSONArray getSjdfDetail(String departmentid,String year){
        JSONArray jsonArray = new JSONArray();
        RecordSet rs = new RecordSet();
        BaseBean baseBean = new BaseBean();
        //1-12月
        String one = "0";
        String two = "0";
        String thre = "0";
        String fou = "0";
        String fiv = "0";
        String six = "0";
        String sev = "0";
        String eig = "0";
        String nig = "0";
        String ten = "0";
        String ele = "0";
        String twef = "0";
        String sql = "select isnull(cast(sjdf as DECIMAL(38,2)),0) as fz," +
                "month(jhksrq) jhksrq,month(jhjsrq) jhjsrq from uf_bmzrw where bm = ? and left(jhksrq,4)= ?";
        rs.executeQuery(sql,departmentid,year);
        baseBean.writeLog(sql+","+departmentid+","+year);
        while (rs.next()){
            int jhksrq = Util.getIntValue(rs.getString("jhksrq"));
            int jhjsrq = Util.getIntValue(rs.getString("jhjsrq"));
            String fz = Util.null2String(rs.getString("fz"));
            String avgfz = fz;
            for(int i = jhksrq;i<=jhjsrq;i++) {
                switch (i) {
                    case 1:
                        one = CalUtil.fAdd( one, avgfz );
                        break;
                    case 2:
                        two = CalUtil.fAdd( two, avgfz );
                        break;
                    case 3:
                        thre = CalUtil.fAdd( thre, avgfz );
                        break;
                    case 4:
                        fou = CalUtil.fAdd( fou, avgfz );
                        break;
                    case 5:
                        fiv = CalUtil.fAdd( fiv, avgfz );
                        break;
                    case 6:
                        six = CalUtil.fAdd( six, avgfz );
                        break;
                    case 7:
                        sev = CalUtil.fAdd( sev, avgfz );
                        break;
                    case 8:
                        eig = CalUtil.fAdd( eig, avgfz );
                        break;
                    case 9:
                        nig = CalUtil.fAdd( nig, avgfz );
                        break;
                    case 10:
                        ten = CalUtil.fAdd( ten, avgfz );
                        break;
                    case 11:
                        ele = CalUtil.fAdd( ele, avgfz );
                        break;
                    case 12:
                        twef = CalUtil.fAdd( twef, avgfz );
                        break;
                    default:
                }
            }
        }

        jsonArray.add(one);
        jsonArray.add(two);
        jsonArray.add(thre);
        jsonArray.add(fou);
        jsonArray.add(fiv);
        jsonArray.add(six);
        jsonArray.add(sev);
        jsonArray.add(eig);
        jsonArray.add(nig);
        jsonArray.add(ten);
        jsonArray.add(ele);
        jsonArray.add(twef);
        return jsonArray;
    }

}
